//
//  StatusCell.swift
//  weibo 666
//
//  Created by mac on 15/11/10.
//  Copyright © 2015年 mac. All rights reserved.
//

import UIKit
///微博Cell控件间的距离
let StatusCellMagrin: CGFloat = 12
///微博Cell头像的大小
let StatusIconWidth: CGFloat = 35
///微博Cell
class StatusCell: UITableViewCell{
    
    
    
    //构造函数
    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        setupUI()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    ///视图模型
    var viewModel: StatusViewModel?{
        didSet {
            topView.viewModel = viewModel
            contentLabel.text = viewModel!.status.text
        }
    }
    
    //MARK: - 懒加载控件
    ///顶部视图信息
    private lazy var topView: StatusTopCell = StatusTopCell()
    
    ///微博文字
    private lazy var contentLabel: UILabel = UILabel(title: "微博正文", fontSize: 20, color: UIColor.redColor(), screenInset: StatusCellMagrin)
    
    ///底部操作视图
    private lazy var bottomView: StatusBottomCell = StatusBottomCell()
    
}
//MARK: - 设置界面
extension StatusCell {
    private func setupUI(){
        //设置背景颜色
        backgroundColor = UIColor.whiteColor()
        
        // 1. 添加控件
        contentView.addSubview(topView)
        contentView.addSubview(contentLabel)
        contentView.addSubview(bottomView)
        
        // 2. 自动布局
        // 1> 顶部视图
        topView.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(contentView.snp_top)
            make.left.equalTo(contentView.snp_left)
            make.right.equalTo(contentView.snp_right)
            make.height.equalTo(2 * StatusCellMagrin + StatusIconWidth)
        }
        
        // 2> 内容标签
        contentLabel.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(topView.snp_bottom).offset(StatusCellMagrin)
            make.left.equalTo(contentView.snp_left).offset(StatusCellMagrin)
        }
        
        // 3> 底部视图
        bottomView.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(contentLabel.snp_bottom).offset(StatusCellMagrin)
            make.left.equalTo(contentView.snp_left)
            make.right.equalTo(contentView.snp_right)
            make.height.equalTo(44)
            
            // 向下约束
            make.bottom.equalTo(contentView.snp_bottom)
        }
    }
}


